<?php

class BancoController extends Zend_Controller_Action
{
    public function init()
    {

    }

    public function indexAction(){
            $this->redirect('/banco/listar');
    }

    public function criarAction(){
        $this->_helper->viewRenderer->setNoRender();

        $post = $this->getAllParams();
       
        if (!is_null($this->getParam('msg')))
            $this->view->msg = Messages::getMessage($this->getParam('msg'));

        if (!empty($post['nome'])){
             
                $tBanco = new DbTable_Banco();
                $banco = $tBanco->createRow($this->getAllParams());
                $banco->nome = $post['nome'];
                $banco->status_banco = Status::DESBLOQUEADO;
                $banco->save();
                $this->redirect('/banco/listar/msg/5');
        }
    }
    
    
    public function listarAction(){
        if (!is_null($this->getParam('msg')))
            $this->view->msg = Messages::getMessage($this->getParam('msg'));
        
        $tBanco = new DbTable_Banco();
        
        $this->view->bancos = $tBanco->fetchAll();
    }
    
    
    public function editarAction(){
        $this->_helper->viewRenderer->setNoRender();
        
        $post = $this->getAllParams();
        
        $tBanco = new DbTable_Banco();
        $banco = $tBanco->find($this->getParam('id'))->current();
    
        if (!empty($post['nome'])){
            $banco->nome = $post['nome'];
            $banco->save();
            $this->redirect('/banco/listar/msg/5');
        }
    }
    
    
    public function ajaxBloquearAction(){
        $this->_helper->viewRenderer->setNoRender();
        
         $tBanco = new DbTable_Banco();
     
         $banco = $tBanco->find($this->getParam('id'))->current();
         
         if ((int) $banco->status_banco === Status::DESBLOQUEADO)
            $banco->status_banco = 1;
         else
             $banco->status_banco = 0;
         
        $banco->save();
        $this->redirect('/banco/listar/msg/5');
    }
   	
}

